package cron

import (
	"github.com/robfig/cron/v3"
	"kill/common/models/mysql"
	"log"
)

var StatusCode = map[int]string{
	0: "WAIT_BUYER_PAY",
	2: "TRADE_SUCCESS",
	1: "TRADE_CLOSED",
}

func GetOrderStatus(orderId string) {
	c := cron.New(cron.WithSeconds())
	c.AddFunc("0 */30 * * * ?", func() {
		o := mysql.Order{}
		if !o.GetOrderStatus(orderId) {
			return
		}
		if o.Status == 0 {
			if !o.UpdateOrderStatus(orderId, 1) {
				log.Println("状态修改失败")
				return
			}
		}
		if o.Status == 1 {
			c.Stop()
		}
	})
	c.Start()
}
